package util;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;

public class TextUtil {

	public static final String CPID = "liuxianshengRR";
	public static final String CPPWD = "111111";

	public static void sendText(String to, String content) throws Exception {
		HttpClient client = new HttpClient();
		Integer num = null;
		String ret = null;
		StringBuffer html = new StringBuffer();
		try {
			String tempbf;
			StringBuffer sb = new StringBuffer("http://hl.my2my.cn/sms/push_mt.jsp");
			sb.append("?cpid=" + CPID);
			sb.append("&cppwd=" + CPPWD);
			sb.append("&phone=" + to);
			sb.append("&msgcont=").append(URLEncoder.encode(content + "【联行支付】", "GBK"));
			GetMethod method = new GetMethod(sb.toString());
			client.executeMethod(method);
			InputStream txtis = method.getResponseBodyAsStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(txtis));
			int count = 0;
			while ((tempbf = br.readLine()) != null) {
				if (count == 0)
					ret = tempbf;
				++count;
				html.append(tempbf);
			}
			try {
				num = Integer.valueOf(ret);
			} catch (NumberFormatException e) {
				num = new Integer(-1);
			}
			if (num.intValue() == 0) {
				System.out.println("返回正确代码:" + ret);
			}
		} catch (Exception ex) {
			ex.printStackTrace();

		}
	}

	public static void main(String[] args) throws Exception {
		sendText("15063337733", "这是一条测试短信,来自于联行支付,发送时间为[" + new SimpleDateFormat("yyyy年MM月dd日HH点mm分ss秒").format(new Date()) + "],请校验接收时间延迟量...");
	}
}
